<?php
class Application_Model_Resources extends Xend_Db_Model {
	public function __construct() {
		parent::__construct();
	}

	public function getDbTable() {
		if(null === $this->_dbTable) {
			$this->setDbTable('Application_Model_Table_Resources');
		}

		return $this->_dbTable;
	}

	public function find($id, Application_Model_Schema_Resources $resource = null) {
		$select = $this->_database
			->select()
			->from(
				array('resources'),
        array(
					'resources.id', 'resources.name', 'resources.max_value')
			)
			->where('resources.id = ?', $id);
		$data	= $this->fetch($select);
		
		if(empty($data) === false) {
			if($resource === null) {
				$resource = new Application_Model_Schema_Resources();
			}	
			
			foreach($data as $k => $v) {
				$resource
					->setId($v['resources']['id'])
					->setName($v['resources']['name'])
					->setMaxValue($v['resources']['max_value']);				
			}
		}
		
		return $resource;
	}

	public function findall() {
		$resources	= array();
		$select			= $this->_database
			->select()
			->from(
				array('resources'),
        array(
					'resources.id', 'resources.name', 'resources.max_value')
			);
		$data	= $this->fetch($select);
		
		if(empty($data) === false) {
			foreach($data as $k => $v) {
				$resource = new Application_Model_Schema_Resources();				
				$resource
					->setId($v['resources']['id'])
					->setName($v['resources']['name'])
					->setMaxValue($v['resources']['max_value']);
				
				$resources[] = $resource;
			}
		}
		
		return $resources;
	}	
}
?>